import request from '@/utils/request'

// 查询巡检配置列表
export function listInspectionConfig(query) {
  return request({
    url: '/ldzl-sb/inspection/config/list',
    method: 'get',
    params: query
  })
}

// 查询巡检配置详细
export function getInspectionConfig(configId) {
  return request({
    url: '/ldzl-sb/inspection/config/' + configId,
    method: 'get'
  })
}

// 新增巡检配置
export function addInspectionConfig(data) {
  return request({
    url: '/ldzl-sb/inspection/config',
    method: 'post',
    data: data
  })
}

// 修改巡检配置
export function updateInspectionConfig(data) {
  return request({
    url: '/ldzl-sb/inspection/config',
    method: 'put',
    data: data
  })
}

// 删除巡检配置
export function deleteInspectionConfig(configId) {
  return request({
    url: '/ldzl-sb/inspection/config/' + configId,
    method: 'delete'
  })
}

// 更新巡检配置状态
export function updateInspectionConfigStatus(configId, status) {
  return request({
    url: '/ldzl-sb/inspection/config/changeStatus',
    method: 'put',
    data: {
      configId,
      configStatus: status
    }
  })
}

// 校验巡检配置编号是否唯一
export function checkConfigCodeUnique(data) {
  return request({
    url: '/ldzl-sb/inspection/config/checkConfigCodeUnique',
    method: 'post',
    data: data
  })
}

// 查询巡检项
export function getInspectionItems(configId) {
  // 使用模拟数据，不调用后端API
  return new Promise(async (resolve) => {
    await delay(200);
    const config = inspectionConfigList.find(item => item.id == configId);
    if (config && config.items) {
      resolve(createResponse(null, config.items, config.items.length));
    } else {
      resolve(createResponse(null, [], 0));
    }
  });
}

// 获取设备类型列表
export function getEquipmentTypeList() {
  return request({
    url: '/ldzl-sb/equipment/type/list',
    method: 'get'
  })
}

// 根据设备类型获取巡检配置
export function getConfigsByTypeId(typeId) {
  return request({
    url: '/ldzl-sb/inspection/config/type/' + typeId,
    method: 'get'
  })
} 